package com.kcht.itsed.mws.devicescheduler;

import com.kcht.itsed.mws.alespecadapter.facade.IMwsPluginRegister;
import com.kcht.itsed.mws.commmodel.PhysicalReaderTemplate;
import com.kcht.itsed.mws.devicescheduler.facade.IPhysicalReaderDriverRegister;
import com.tjkcht.midware.reader.Rd30Manager;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;

import java.util.LinkedList;

@Component
@Slf4j
public class ReaderDriverRegister implements ApplicationListener<ReaderRegisterEvent> {
	
	@Autowired
	private IMwsPluginRegister mwsPluginRegister;

	@SuppressWarnings("serial")
	public void registerRd30Driver( IPhysicalReaderDriverRegister driverRegister) {
		log.info("注册RD30的驱动");
		driverRegister.registerPhysicalReaderDriver("RD30", new Rd30Manager());
		PhysicalReaderTemplate kchtReaderTemplate = new PhysicalReaderTemplate(){{
			setAntennaTemplateList(new LinkedList<AntennaProtocolTemplate>(){{
				add(new AntennaProtocolTemplate(1, new String[]{"EPC"}));
				add(new AntennaProtocolTemplate(2, new String[]{"EPC"}));
				add(new AntennaProtocolTemplate(3, new String[]{"EPC"}));
				add(new AntennaProtocolTemplate(4, new String[]{"EPC"}));
			}});
		}};
		
		mwsPluginRegister.registerDeviceClass("KC-RD30", "科畅慧通RD30型超高频阅读器",kchtReaderTemplate);
	}

	@Override
	public void onApplicationEvent(ReaderRegisterEvent event) {
		registerRd30Driver((IPhysicalReaderDriverRegister) event.getSource());
	}
}
